<!doctype html>
<html lang="en">
<head>
    <title>登录到短链接服务</title>
    <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport'/>
</head>
<style>
    html, body {
        height: 100%;
    }

    * {
        margin: 0;
        padding: 0;
    }
</style>
<body>
<iframe src="http://${host}?appId=${appId}" style="height:100%;width:100%;border:0;"></iframe>
</body>


<script>
    if (!window.__LISTEN_LOGIN_IFRAME__) {
        window.__LISTEN_LOGIN_IFRAME__ = true;
        window.addEventListener('message', function (e) {
            if (e.data && typeof e.data === 'string') {
                try {
                    var message = JSON.parse(e.data);
                    console.log(message);
                    if (message.type === 'LOGIN_SUCCESS') {
                        localStorage.setItem("loginInfo", JSON.stringify(message));
                        window.location.href = "${redirectUrl}"
                    } else if (message.type === 'REGISTER_SUCCESS') {
                        localStorage.setItem("loginInfo", JSON.stringify(message));
                        window.location.href = "${redirectUrl}"
                    } else {
                        alert("登录失败," + message);
                        window.location.href = "/user/login"
                    }
                } catch (e) {
                    alert("登录失败," + e);
                    window.location.href = "/user/login"
                }
            }
        });
    }
</script>
<script src="/assets/js/jquery.min.js" type="text/javascript"></script>
</html>
